import renohomeRightNav from '@/components/CustormStyle/renohome_right_nav'
export default {
  data() {
    return {
      nrActive: true,
      fgActive: false,
      tiActive: false,
      $uploadType: -1,
      $periods_show:false,
    }
  },
  computed: {
    getPath() {
      return function(path) {
        return (path.includes('https://') || path.includes('http://')) ? `${path}` : require(`@/assets/custorm_style/${path}`)
      }
    }
  },
  props: {
    defaultConfig: {
      type: Object,
      required: true
    },
    custormItemData: Object,
    custormEditEvt: Function,
    custormIndex: Number,
    custormCurrent: Number
  },
  components: {
    renohomeRightNav
  },
  methods: {
    conversionType(type, value) {
      if (type === 'number') {
        return typeof value !== 'number' ? Number(value) : value
      }
    },
    rightNavChange(e) {
      if (e === 'count') {
        this.nrActive = true
        this.fgActive = false
        this.tiActive = false
      } else if (e === 'title') {
        this.nrActive = false
        this.fgActive = false
        this.tiActive = true
      } else {
        this.nrActive = false
        this.fgActive = true
        this.tiActive = false
      }
    },
    changePattern(e) {
      this.$nextTick(() => {
        this.custormItemData.style.display = e
      })
    },
    addItemList({ data, max = null, itemCopy }) {
      const listArr = data
      if (itemCopy) {
        if (typeof max === 'number') {
          const isMax = listArr.length < max
          if (!isMax) {
            this.$message({
              type: 'error',
              message: `添加失败，此组件最多添加${max}个~!`
            })
            return
          }
        }

        this.$nextTick(() => {
          listArr.push(itemCopy)
        })
      }
    },
    delItemList({ data, min = 1, index = -1 }) {
      const listArr = data
      if (index !== -1) {
        if (listArr.length <= min) {
          this.$message({
            type: 'error',
            message: `删除失败，此组件至少保留${min}个`
          })
        } else {
          this.$alert('确定删除此选项？', '提示', {
            confirmButtonText: '确定',
            callback: action => {
              if (action === 'confirm') {
                listArr.splice(index, 1)
                this.$message({
                  type: 'success',
                  message: `删除成功`
                })
              }
            }
          })
        }
      }
    },
    output(config) {
      console.log(config, '===================uploadConfig')
      if(config.params.params_type){
        if(config.params.params_type==='periods_radio'){
          this.$periods_show=true
        }
      }
      if (
        Object.prototype.toString.call(this.custormEditEvt) === '[object Function]'
      ) {

        this.$uploadType = config.type || -1
        // console.log(" this.custormEditEvt this.custormEditEvt", this.custormEditEvt)
        this.custormEditEvt(config)
      }
    }
  }
}
